<?php
session_start(); // start PHP session

require_once "config.php"; // use a config file

$dir_contents = scandir($wikidir);
sort($dir_contents);

// since this will count the . and .., make sure it is larger than 2
if (count($dir_contents) > 2) {
    print '<ol>';
    foreach ($dir_contents as $content) {
        if ($content != '.' && $content != '..') {
            if (is_file($wikidir . "/" . $content)) { 
                $filename = str_replace(".wiki", "", $content);
                print "<li><a href='index.php?f=$filename'>$content</a></li>";
            }
            else
            {
                print "<li>directory[$content] - <a href='toc.php?d=$content'>see contents</a></li>";
            }
        }
    }    
    print '</ol>';
}

/* 
 * function to output directory structure of a directory as a PHP data object
 * a workable data object would be:
 * dir[level1: array(file1, file2, directory1: array(file1, file2), file3]
 */
function create_directory_structure($dir) {

}

/*
$dir = array(
        'files' => array(file1, file2);
        'directories' =>array(dir1 => array(
                                      'files' => array(file1, file2),
                                      'directories' => array(dir1 => array('files' => array(file1, file2), 'directories' => array())),
                              dir2 => array(
                                      'files' => array(),
                                      'directories' => array(),
                                      )
                              )
        )
        );
*/
